import React, { Component, Fragment } from 'react';
import { DatePicker, Button, Space, Modal, Radio, Form, Input, Row, Col, message, Select, Result } from 'antd'
import { connect } from 'dva';
const { Option } = Select;

class PatentDataSearchForm extends Component {
    constructor(props) {
        super(props)
    }

    formRef = React.createRef()

    onFinish = values => {
        if(values.applicationDate){
            values.applicationDate = values.applicationDate.format("YYYY-MM-DD")
        }
       
        if(values.publicationDate){
            values.publicationDate = values.publicationDate.format("YYYY-MM-DD")
        }

        this.props.dispatch({
            type:"patentData/setPagination",
            data:{
                pageSize:10,
                current:1
            }
        })

        this.props.dispatch({
            type:"patentData/setQueryParam",
            data:{...values}
        })

        this.props.dispatch({
            type:"patentData/getPatentDataSearch",
        })
    }

    resetForm = () => {
        this.formRef.current.resetFields(['patentTitle','publicationNumber','publlcationDate',
            'ipc','applicantProvince','publlcationCountry','inventor','applicationDate','patentType',
            'applicantType','mainClassification','applicationNumber','applicant'
        ])

        this.props.dispatch({
            type:"patentData/setQueryParam",
            data:{}
        })

        this.props.dispatch({
            type:"patentData/setPagination",
            data:{
                pageSize:10,
                current:1
            }
        })

        this.props.dispatch({
            type:"patentData/getPatentDataTableList"
        })
    }

    reload = () => {
        window.location.reload()
    }

    render() {
        return (
            <Form
                name="patentDataSearch"
                onFinish={this.onFinish}
                onFinishFaild={this.onFinishFaild}
                ref={this.formRef}
            >
                <Row>
                    <Col span={4}>
                        <Form.Item
                            label="专利标题"
                            name="patentTitle"
                        >
                            <Input placeholder={`例：重金属`}/>
                        </Form.Item>
                    </Col>
                    <Col span={4} push={1}>
                        <Form.Item
                            label="公开号"
                            name="publicationNumber"
                        >
                            <Input placeholder={`例：CN106984641B`}/>
                        </Form.Item>
                    </Col>
                    <Col span={4} push={2}>
                        <Form.Item
                            label="公开日"
                            name="publicationDate"
                        >
                            <DatePicker></DatePicker>
                        </Form.Item>
                    </Col>
                    <Col span={4} push={3}>
                        <Form.Item
                            label="ipc分类号"
                            name="ipc"
                        >
                            <Input placeholder={`例：B09C1/08`}/>
                        </Form.Item>
                    </Col>
                    <Col span={4} push={4}>

                        <Form.Item
                            label="申请人省市"
                            name="applicantProvince"
                        >
                            <Input placeholder={`例：湖南; 43`}/>
                        </Form.Item>
                    </Col>
                </Row>
                <Row>
                    <Col span={4}>
                        <Form.Item
                            label="公开国别"
                            name="publicationCountry"
                        >
                            <Input placeholder={`例：CN`}/>
                        </Form.Item>
                    </Col>
                    <Col span={4} push={1}>
                        <Form.Item
                            label="发明人"
                            name="inventor"
                        >
                            <Input placeholder={`例：张三`}/>
                        </Form.Item>
                    </Col>
                    <Col span={4} push={2}>
                        <Form.Item
                            label="申请日"
                            name="applicationDate"
                        >
                            <DatePicker></DatePicker>
                        </Form.Item>
                    </Col>
                    <Col span={4} push={3}>
                        <Form.Item
                            label="专利类型"
                            name="patentType"
                        >
                            <Select placeholder={`专利类型`} showArrow={false}>
                                <Option value="发明授权">发明授权</Option>
                                <Option value="实用新型">实用新型</Option>
                                <Option value="外观设计">外观设计</Option>
                            </Select>
                        </Form.Item>
                    </Col>
                    <Col span={4} push={4}>
                        <Form.Item
                            label="申请人类型"
                            name="applicantType"
                        >
                            <Select placeholder={`申请人类型`} showArrow={false}>
                                <Option value="个体">个体</Option>
                                <Option value="企业">企业</Option>
                                <Option value="高校">高校</Option>
                                <Option value="科研单位">科研单位</Option>
                                <Option value="产学合作">产学合作</Option>
                                <Option value="大专院校">大专院校</Option>
                                <Option value="其他">其他</Option>
                            </Select>
                        </Form.Item>
                    </Col>
                </Row>
                <Row>
                    <Col span={4}>
                        <Form.Item
                            label="主分类号"
                            name="mainClassification"
                        >
                            <Input placeholder={`例：C04B28/30`}/>
                        </Form.Item>
                    </Col>
                    <Col span={4} push={1}>
                        <Form.Item
                            label="申请号"
                            name="applicationNumber"
                        >
                            <Input placeholder={`例：CN201710243513.9`}/>
                        </Form.Item>
                    </Col>
                    <Col span={4} push={2}>
                        <Form.Item
                            label="申请人"
                            name="applicant"
                        >
                            <Input placeholder={`例：李四`}/>
                        </Form.Item>
                    </Col>
                    <Col span={4} push={4}>
                        <Space style={{marginLeft:153}}>
                            <Button type="primary" htmlType="submit">查询</Button>
                            <Button onClick={this.resetForm}>重置</Button>
                            <Button onClick={this.reload}>刷新</Button>
                        </Space>
                    </Col>
                </Row>

            </Form>
        )
    }
}


export default connect()(PatentDataSearchForm)